package stark.app.function.pixeldraw;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;

import androidx.annotation.Nullable;

import com.stark.pixeldraw.lib.ui.PixelDrawEditActivity;
import com.stark.pixeldraw.lib.ui.PixelDrawImportActivity;

import stark.app.R;
import stark.app.base.BaseWithFragmentActivity;
import stark.app.databinding.FragmentPixelDrawDemoBinding;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.utils.IntentUtil;

/**
 * Author：daizhongbin on 2024/4/12
 * Email：1027154338@qq.com
 * Desc:
 */
public class PixelDrawDemoFragment extends BaseNoModelFragment<FragmentPixelDrawDemoBinding> {

    private static final int REQ_IMAGE = 1;

    @Override
    protected int onCreate() {
        return R.layout.fragment_pixel_draw_demo;
    }

    @Override
    protected void initView() {
        mDataBinding.btnImport.setOnClickListener(v -> {
            IntentUtil.pickImage(this, REQ_IMAGE);
        });
        mDataBinding.btnCreate.setOnClickListener(v -> {
            PixelDrawEditActivity.start(getActivity(), new int[48 * 48], 48);
        });
        mDataBinding.btnRecord.setOnClickListener(v -> {
            BaseWithFragmentActivity.start(getContext(), "像素画记录", PixelDrawRecordFragment.class);
        });
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != Activity.RESULT_OK) return;
        if (data != null) {
            Uri imgUri = data.getData();
            PixelDrawImportActivity.startWithImgUri(getActivity(), imgUri);
        }
    }
}
